home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8748 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  60 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.express.ca!not-for-mail
  3. From: gchan@express.ca (Gary Chan)
  4. Subject: function to format float number
  5. Message-ID: <367cc$0321.121@news.express.ca>
  6. Date: Wed, 06 Mar 1996 08:50:01 GMT
  7. X-Newsreader: WinVN 0.99.6
  8. MIME-Version: 1.0
  9. Content-Type: Text/Plain; charset=US-ASCII
  10.  
  11. I need a function to convert a floating point number to a formatted 
  12. dollar value string.  Eg.  1234 becomes $1,234.00
  13.  
  14. I need help implementing my "cformat" function:
  15.  
  16. #include <stdio.h>
  17. #include <ctype.h>
  18. #define MAX_STRLEN 20 //maximum length of input string
  19. #define NONUM 0
  20. #define YESNUM 1
  21.  
  22. int GetFloat(float *n);
  23. char cformat(float n, char buff);
  24. int main()
  25.  
  26. {
  27. float number;
  28. int status;
  29. char buff[MAX_STRLEN + 1];
  30.  
  31. printf("\n\nEnter a number: ");
  32. status = GetFloat(&number);
  33.  
  34. //printf("Status is %d", status);
  35. switch(status)
  36.     {
  37.     case YESNUM:    cformat(number, *buff);
  38.                     printf("The formatted number is 
  39. %s\n", buff);
  40.                     break;
  41.     case NONUM:        printf("Cannot format\n");
  42.                     break;
  43.     default:        break;
  44.     }
  45.  
  46.  
  47.  
  48. return(0);
  49. }
  50.  
  51. char cformat(float n, char *buff)
  52.  
  53. {
  54. ???
  55. }
  56. *******************
  57. Thanks in advance.
  58.  
  59.  
  60.